<script setup lang="tsx">
import { ApideveloperApi } from '@/api-services';
import { feature, getAPI } from '@/axios-utils';
import { $t } from '@/locales';
import { queryDone } from '@/utils/api';
import { ref } from 'vue';


const loadingDefaultCodeGenerate = ref<boolean>(false);
const loadingPermissionGenerate = ref<boolean>(false);

async function handleDefaultCodeGenerate()
{
  console.log('handleDefaultCodeGenerate');
  loadingDefaultCodeGenerate.value = true
  const [err, res] = await feature(
    getAPI(ApideveloperApi).defaultCodeGenerate(),
  );
  queryDone(err, async () => {
    if (res?.data.succeeded) {
      window.$message?.success($t("common.success"));
    }
    loadingDefaultCodeGenerate.value = false;
  });
}

async function handlePermissionGenerate(){
  console.log('handlePermissionGenerate');
  loadingPermissionGenerate.value = true
  const [err, res] = await feature(
    getAPI(ApideveloperApi).permissionGenerate("api"),
  );
  queryDone(err, async () => {
    if (res?.data.succeeded) {
      window.$message?.success($t("common.success"));
    }
    loadingPermissionGenerate.value = false;
  });
}

</script>

<template>
  <div>
    <ElSpace wrap>
      <ElButton type="primary" @click="handleDefaultCodeGenerate" :loading="loadingDefaultCodeGenerate">{{
        $t("page.sysSetting.dev.btnDefaultCodeGenerate")
      }}</ElButton>
      <ElButton type="primary" @click="handlePermissionGenerate" :loading="loadingPermissionGenerate">{{
        $t("page.sysSetting.dev.btnPermissionGenerate")
      }}</ElButton>
    </ElSpace>

  </div>
</template>

<style scoped></style>
